<script setup>
import { useRouter } from "vue-router";
import { adminLogout } from "@/apis/admin/user";
import { ref, computed } from "vue";

import {
  List,
  Document,
  Menu as IconMenu,
  Grid,
  Comment,
  Histogram,
  UserFilled,
  WarnTriangleFilled,
  Checked,
  SwitchButton,
  Switch,
} from "@element-plus/icons-vue";

// 获取路由对象：单例模式
const route = useRouter();

/**
 * 退出登录
 */
const quit = () => {
  route.push("/");
  // 清空缓存
  sessionStorage.clear;
};

const isCollapse = ref(true);
const asideWidth = computed(() => (isCollapse.value ? "64px" : "240px"));

const toggleMenu = () => {
  isCollapse.value = !isCollapse.value;
};
</script>
<template>
  <el-container>
    <el-header class="el-header">
      <el-menu mode="horizontal" :ellipsis="false" class="nav-menu">
        <div class="logo-section">
          <span class="title">基于协同过滤算法的智慧校园活动系统</span>
          <span class="subtitle">后台系统</span>
        </div>
        <div class="user-actions">
          <el-button class="logout-btn" @click="quit">
            <el-icon><SwitchButton /></el-icon>
            退出登录
          </el-button>
        </div>
      </el-menu>
    </el-header>

    <el-container class="main-container">
      <el-aside :width="asideWidth" class="el-aside">
        <el-scrollbar class="el-aside-scrollbar">
          <el-menu
            :default-active="$route.path"
            class="el-left-menu"
            :router="true"
            :collapse="isCollapse"
          >
            <div class="menu-header">
              <el-button class="collapse-btn" @click="toggleMenu">
                <el-icon><Switch /></el-icon>
              </el-button>
            </div>
            <el-menu-item index="/admin/overview">
              <el-icon><Histogram /></el-icon>
              <template #title>仪表盘</template>
            </el-menu-item>
            <el-menu-item index="/admin/manage">
              <el-icon><UserFilled /></el-icon>
              <template #title>用户管理</template>
            </el-menu-item>
            <el-menu-item index="/admin/activity">
              <el-icon><icon-menu /></el-icon>
              <template #title>活动管理</template>
            </el-menu-item>
            <el-menu-item index="/admin/activity-signup">
              <el-icon><List /></el-icon>
              <template #title>发布活动管理</template>
            </el-menu-item>
            <el-menu-item index="/admin/category">
              <el-icon><Checked /></el-icon>
              <template #title>活动分类管理</template>
            </el-menu-item>
            <!-- <el-menu-item index="/admin/userbehavior">
              <el-icon><Grid /></el-icon>
              <template #title>用户行为管理</template>
            </el-menu-item> -->
            <el-menu-item index="/admin/comment">
              <el-icon><Comment /></el-icon>
              <template #title>评论管理</template>
            </el-menu-item>
            <el-menu-item index="/admin/op-log">
              <el-icon><WarnTriangleFilled /></el-icon>
              <template #title>用户操作日志</template>
            </el-menu-item>
          </el-menu>
        </el-scrollbar>
      </el-aside>

      <el-main class="main-content">
        <el-scrollbar class="main-scrollbar">
          <router-view />
        </el-scrollbar>
      </el-main>
    </el-container>
  </el-container>
</template>

<style lang="less" scoped>
.el-header {
  padding: 0;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  position: relative;
  z-index: 100;
}

.nav-menu {
  display: flex;
  justify-content: space-between;
  height: 64px;
  padding: 0 24px;
  border: none;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.title {
  font-size: 20px;
  font-weight: 600;
  background: linear-gradient(45deg, #1a237e, #3949ab);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 14px;
  color: #666;
  padding: 4px 12px;
  background: #f5f5f5;
  border-radius: 12px;
}

.user-actions {
  display: flex;
  align-items: center;
}

.logout-btn {
  height: 36px;
  padding: 0 20px;
  border-radius: 18px;
  font-size: 14px;
  font-weight: 500;
  color: #666;
  border: 2px solid #e4e4e4;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 6px;

  &:hover {
    color: #3949ab;
    border-color: #3949ab;
    background: rgba(57, 73, 171, 0.04);
  }
}

.main-container {
  height: calc(100vh - 64px);
}

.el-aside {
  background: #fff;
  border-right: 1px solid #eee;
  transition: width 0.3s ease;
}

.el-aside-scrollbar {
  height: 100%;

  :deep(.el-menu) {
    border-right: none;
  }

  :deep(.el-menu-item) {
    height: 50px;
    line-height: 50px;
    margin: 8px 16px;
    border-radius: 8px;

    &.is-active {
      width: 200px;
      background: linear-gradient(45deg, #1a237e, #3949ab);
      color: white;
    }

    &:hover:not(.is-active) {
      background: #f5f5f5;
      color: #3949ab;
    }

    .el-icon {
      font-size: 18px;
    }
  }
}

.main-content {
  background: #f8f9fa;
  padding: 24px;
}

.main-scrollbar {
  height: 100%;
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.menu-header {
  padding: 16px;
  display: flex;
  justify-content: flex-end;
}

.collapse-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: transparent;
  color: #666;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  border-radius: 8px;

  &:hover {
    background: #f5f5f5;
    color: #3949ab;
  }

  .el-icon {
    font-size: 20px;
    transition: transform 0.3s ease;
  }
}

.el-left-menu {
  transition: width 0.3s ease;

  &:not(.el-menu--collapse) {
    width: 240px;
  }
}

:deep(.el-menu--collapse) {
  .el-menu-item {
    padding: 0 !important;
    justify-content: center;
  }
}
</style>
